<template>
  <div id="nav">
    <!-- <router-link to="/">主页</router-link> |
    <router-link to="/Login">登录</router-link> -->
  </div>
  <router-view/>
</template>

<script>
export default {
  created(){
    // 刷新页面防止数据丢失
    // 刷新之前临时存储用户信息和标签信息
    let store = this.$store
    window.onbeforeunload = function () {
      sessionStorage.setItem('dynamicTags',JSON.stringify(store.state.Tags.dynamicTags))
      sessionStorage.setItem('datas',JSON.stringify(store.state.Login.datas))
    }
  },
  mounted(){
    // 刷新之后标签还在
    // 挂载后（页面重新渲染）把刷新之前临时存储用户信息和标签信息还原回来，并且立即删除临时存储信息
    let store = this.$store
    let dynamicTags =JSON.parse(sessionStorage.getItem("dynamicTags"))
    let datas = JSON.parse(sessionStorage.getItem("datas"))
    if(dynamicTags&&datas){
      store.state.Tags.dynamicTags = dynamicTags
      store.state.Login.datas = datas
      sessionStorage.removeItem("dynamicTags")
      sessionStorage.removeItem("datas")

    }

  }
}
</script>
<style lang="less" scoped>
body{
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  // padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
